// RectProperties.cpp : implementation file
//

#include "stdafx.h"
#include "resourcemake.h"
#include "RectProperties.h"
#include "resourcemakeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRectProperties dialog


CRectProperties::CRectProperties(CWnd* pParent /*=NULL*/)
	: CDialog(CRectProperties::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRectProperties)
	m_LineWidth = -1;
	m_alpha = 0;
	//}}AFX_DATA_INIT
}


void CRectProperties::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRectProperties)
	DDX_Control(pDX, IDC_FILLCOLOR, m_BtnFillColor);
	DDX_Control(pDX, IDC_LINECOLOR, m_BtnLineColor);
	DDX_CBIndex(pDX, IDC_LINEWIDTH, m_LineWidth);
	DDX_Text(pDX, IDC_FILLALPHA, m_alpha);
	DDV_MinMaxInt(pDX, m_alpha, 0, 255);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRectProperties, CDialog)
	//{{AFX_MSG_MAP(CRectProperties)
	ON_BN_CLICKED(IDC_FILLCOLOR, OnFillcolor)
	ON_BN_CLICKED(IDC_LINECOLOR, OnLinecolor)
	ON_CBN_SELCHANGE(IDC_LINEWIDTH, OnSelchangeLinewidth)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRectProperties message handlers

void CRectProperties::OnFillcolor() 
{
	// TODO: Add your control notification handler code here
	( (CResourcemakeDlg*) AfxGetApp()->m_pMainWnd) ->m_IsSaveSsml = FALSE;

	CColorDialog dlg(m_FillColor); 
	if (dlg.DoModal()==IDOK)
	{
		m_bFill = true;
		m_FillColor=dlg.GetColor();
		CString str_RGB;
		str_RGB.Format("%d:%d:%d",GetRValue(m_FillColor),GetGValue(m_FillColor),GetBValue(m_FillColor));
		this->m_BtnFillColor.SetWindowText(str_RGB);
		m_pCurrObj->m_bFill = m_bFill;
		m_pCurrObj->BrushColor = m_FillColor;
		((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
	}
}

void CRectProperties::OnLinecolor() 
{
	// TODO: Add your control notification handler code here
	( (CResourcemakeDlg*) AfxGetApp()->m_pMainWnd) ->m_IsSaveSsml = FALSE;

	CColorDialog dlg(m_LineColor); 
	if (dlg.DoModal()==IDOK)
	{
		m_LineColor=dlg.GetColor();
		CString str_RGB;
		str_RGB.Format("%d:%d:%d",GetRValue(m_LineColor),GetGValue(m_LineColor),GetBValue(m_LineColor));
		this->m_BtnLineColor.SetWindowText(str_RGB);
		m_pCurrObj->LineColor = m_LineColor;
		((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
	}
	
}

BOOL CRectProperties::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CString str;
	for(int i=0;i<10;i++)
	{
		str.Format("%d",i+1);
		((CComboBox*)GetDlgItem(IDC_LINEWIDTH))->InsertString(i,str);
	}

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRectProperties::OnSelchangeLinewidth() 
{
	// TODO: Add your control notification handler code here
	( (CResourcemakeDlg*) AfxGetApp()->m_pMainWnd) ->m_IsSaveSsml = FALSE;

	int m = ((CComboBox*)GetDlgItem(IDC_LINEWIDTH))->GetCurSel();
	m_LineWidth=m+1;
	m_pCurrObj->LineWidth = m+1;
	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_ddd->Invalidate();
	
}
